package org.jmh.gift.controller;

import org.jmh.gift.service.IGoodsBrandService;
import org.jmh.gift.domain.GoodsBrand;
import org.jmh.gift.query.GoodsBrandQuery;
import org.jmh.gift.util.AjaxResult;
import org.jmh.gift.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.baomidou.mybatisplus.plugins.Page;
@RestController
@RequestMapping("/goodsBrand")
public class GoodsBrandController {
    @Autowired
    public IGoodsBrandService goodsBrandService;


    /**
     * 保存和修改公用的
     * @param goodsBrand  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody GoodsBrand goodsBrand){

            if( goodsBrand.getId()!=null)
                goodsBrandService.updateById(goodsBrand);
            else
                goodsBrandService.insert(goodsBrand);
            return AjaxResult.success();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
            goodsBrandService.deleteById(id);
            return AjaxResult.success();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable("id")Long id)
    {
            GoodsBrand goodsBrand = goodsBrandService.selectById(id);
            return AjaxResult.success(goodsBrand);

    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult list(){

            List< GoodsBrand> list = goodsBrandService.selectList(null);
            return AjaxResult.success(list);

    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult json(@RequestBody GoodsBrandQuery query)
    {

        Page<GoodsBrand> page = new Page<GoodsBrand>(query.getPage(),query.getRows());
        page = goodsBrandService.selectPage(page);
        PageList pageList = new PageList<GoodsBrand>(page.getTotal(),page.getRecords());
            return AjaxResult.success(pageList);

    }




}
